package diningphilosophers;

public class Philosopher {
	private Fork fork1;
	private Fork fork2;
	private int timeLeft;
	private String name;
	public Philosopher(String name,Fork f1, Fork f2, int eatTime) {
		fork1=f1;
		fork2=f2;
		timeLeft=eatTime;
                this.name = name;
	}
	
	public boolean eat() { // True = is eating
		if (!fork1.isInUse()&&!fork2.isInUse()) {
			fork1.setUsing(true);
			fork2.setUsing(true);
			timeLeft--;
			return true;
		}
		else return false;
	}
	
	public int getTimeLeft() {
		return this.timeLeft;
	}
	
	public void stopEating() {
		fork1.setUsing(false);
		fork2.setUsing(false);
	}

        public String getName() { return name; }
}
